import API from "API";
import {request as Request} from "Ajax";
import CustomError from "../utils/CustomError";
module.exports = {
    /*
    * 获取分类
    * */
    getCate: async function () {
        try {
            return await Request({
                url: API.productCate
            })
        } catch (e) {
            throw new CustomError (e, "Product.getCate").parse()
        }
    },

    /*
    * 获取列表信息
    * */
    getList: async function (data = {}) {
        try {
            let res = await Request({
                url: API.productList,
                data
            })
            let copyRes = JSON.parse(JSON.stringify(res));
            copyRes.itemList = copyRes.itemList.map(function (item) {
                return {
                    t_date: item.t_date,
                    c_fund_id: item.c_fund_id,
                    c_fund_name: item.c_fund_name,
                    c_risk_level: item.c_risk_level,
                    c_reg_code: item.c_reg_code,
                    c_fund_type: item.c_fund_type,
                    n_nav: item.n_nav,
                    n_added_nav: item.n_added_nav,
                    n_lastest_m_return: item.n_lastest_m_return
                }
            })
            return copyRes
        } catch (e) {
            throw new CustomError (e, "Product.getList").parse()
        }
    },
    /*
    * 获取详情
    * */
    getDetail: async function (id) {
        try {
            return await Request({
                url: API.productDetail,
                data: {c_fund_id: id}
            })
        } catch (e) {
            throw new CustomError (e, "Product.getDetail").parse()
        }
    },
    /*
    * 获取净值
    * */
    getNv: async function (data) {
        try {
            return await Request({
                url: API.productNv,
                data
            })
        } catch (e) {
            throw new CustomError (e, "Product.getNv").parse()
        }
    },
    /*
    * 获取净值
    * */
    getWeekNv: async function (data) {
        try {
            return await Request({
                url: API.productWeekNv,
                data
            })
        } catch (e) {
            throw new CustomError (e, "Product.getWeekNv").parse()
        }
    },
    /*
    * 预约统计
    * */
    getCensus: async function () {
        try {
            return await Request({
                url: API.productCensus
            })
        } catch (e) {
            throw new CustomError (e, "Product.getCensus").parse()
        }
    }
}